package com.ymxk.window;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.song.floatwindow.FloatConfig;
import com.song.floatwindow.FloatPermission;
import com.song.floatwindow.FloatWindow;

public class MainActivity extends AppCompatActivity {

    private FloatWindow floatWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


//        //可拖动，释放后自动贴边
//        FloatWindow.with(getApplicationContext())
//                .setView(view)
//                .setMoveType(MoveType.slide)
//                .build();

        //FloatingActionActivity.jumpTo(this);
        FloatingRelativeActivity.jumpTo(this);

    }


    public void showClick(View view) {
        FloatPermission floatPermission = new FloatPermission();
        if (floatPermission.isHavePermission(this)) {
            if (floatWindow == null) {
                FloatConfig floatConfig = new FloatConfig();
                View contentView = LayoutInflater.from(this).inflate(R.layout.float_view, null);
                floatConfig.setContentView(contentView);
                floatConfig.setContext(this);
                floatConfig.setStartX(0);
                floatConfig.setStartY((int) (1400 * 0.7));
                floatWindow = new FloatWindow(floatConfig);
            }
            floatWindow.show();
        } else {
            floatPermission.gotoPermission(this);
        }
    }

    public void hideClick(View view) {
        if (floatWindow != null) {
            floatWindow.hidden();
        }
    }

//    public void showClick(View view) {
//        if (floatWindow==null){
//            FloatConfig floatConfig = new FloatConfig();
//            View contentView = LayoutInflater.from(this).inflate(R.layout.float_view, null);
//            floatConfig.setContentView(contentView);
//            floatConfig.setContext(this);
//            floatConfig.setStartX(0);
//            floatConfig.setStartY((int) (1400 * 0.7));
//            floatWindow = new FloatWindow(floatConfig);
//        }
//        floatWindow.show();
//    }

}